<!--
 * @Author: krsea 965837746@qq.com
 * @Date: 2025-02-27 17:36:29
 * @LastEditors: krsea 965837746@qq.com
 * @LastEditTime: 2025-03-04 14:43:02
 * @FilePath: \vue3-code\2306\week2\4.6组件嵌套.html
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>局部组件</title>
    <!-- 引入vue.js -->
    <script src="../js/vue.js"></script>
</head>

<body>
    <!-- 挂载点 -->
    <div id="app">
        <my-component></my-component>
    </div>
    <!-- 定义模板 -->
    <template id="temp1">
        <div>
            <p>我是色板1</p>
            <input type="color" />
        </div>
    </template>
    <template id="temp2">
        <div>
            <p>我是色板2</p>
            <input type="color" />
        </div>
    </template>
    <template id="temp">
        <div>
            <component-a></component-a>
            <component-b></component-b>
        </div>
        <!-- <component-a></component-a>
        <component-b></component-b> -->
    </template>
    <!-- 使用javascript 脚本 -->
    <script type="text/javascript">
        // 定义
        var Child1 = {
            template: '#temp1'
        }
        var Child2 = {
            template: '#temp2'
        }
        // 局部组件的模板 变量   通过一个普通的 JavaScript 对象来定义组件
        var myComponent = {
            template: '#temp',
            components: {
                'component-a': Child1,
                'component-b': Child2
            }
        }
        //创建app vue实例
        var app = new Vue({
            el: '#app',
            //    然后在 components 选项中定义你想要使用的组件
            components: {
                'my-component': myComponent
            }
        })

    </script>
</body>

</html>